from locals import *
import objects

class Monster(objects.Character):
	hostile = True
	
	_passable = True
	_push = False
	
	_immunities = ()
	_damage = ("creature",)
	
	walk_speed = 6
	
	def __init__(self, map, position, direction, float=False):
		super(Monster, self).__init__(map, position, direction)
		
		self.float = float
	
	def save(self, variables):
		if self.float:
			return "%s, %s" % (super(Monster, self).save(variables), "float")
		else:
			return super(Monster, self).save(variables)
	
	def update(self):
		super(Monster, self).update()
		
		if (not all(self.frozen)) and (not self.moving) and (not self.dead):
			self.move(movements[self.direction], self.walk_speed)
	
	def give(self, item):
		return False
	
	def step(self, stepper):
		stepper.kill(self, self._damage)

class Fireball(Monster):
	graphic = "fireball.png"
	_frame_delay = 8
	
	_immunities = ("fire")
	_damage = ("creature", "fire")
	
	walk_speed = 4

	def move(self, movement, speed):		
		if not super(Fireball, self).move(movement, speed):
			self.direction += 1
			if self.direction > 3:
				self.direction -= 4
		
			x, y = self.position
			move_x, move_y = movements[self.direction]
		
			new_position = (x + move_x, y + move_y)
			
			if not self.map.passable(new_position, self):
				self.direction += 2
				if self.direction > 3:
					self.direction -= 4
					
			return False
		else:
			return True
					
class Ball(Monster):
	graphic = "ball.png"

	walk_speed = 8

	def move(self, movement, speed):		
		if not super(Ball, self).move(movement, speed):
			self.direction += 2
			if self.direction > 3:
				self.direction -= 4
